/* @(#)CategoryDown.java   
 *
 * Project: GS-1
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li    2006-7-7     新增
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package system.imp;

import java.io.DataInputStream;

import java.net.URL;

import framework.core.*;
/**
 * 
 */
public class CategoryDown { 
    public void doDown(DBConnection con, ILoginContext loginContext){
        String tResult="";
        DataInputStream dis = null;
        try {            
            LogWriter.info ("Begin to Down Category Data... ");
            String tDay=DateUtil.getNextUpDay(-1);
            //文件下载
            String Name="GW_ManufactureCategory_"+tDay+".xls";
            //URL url = new URL("http" + "://" + "192.168.0.25" + "/" + "v3/back/down" + Name);
            URL url = new URL("http" + "://" + Config.getGSIP() + ":" + Config.getGSPort() + Config.getGSContext() + "/" + Name);
     
            dis = new DataInputStream(url.openStream());
            
            
            try{
                //导入产品分类信息
                tResult = GWFileUploadProcessor.batchImportManufactureCategory(dis, con, loginContext);
            }catch(GWException e){            
                LogWriter.error(e.getMessage());            
            }
            //从返回的值中取得失败和成功的数据
            String tSuccess= tResult.split("-")[0];
            String tFail= tResult.split("-")[1];
            String tOutputPath = tResult.split("-")[2];

            if(Integer.parseInt(tFail)>0){
                LogWriter.error("Fail down Category output path: " + tOutputPath);
                LogWriter.error("Fail import Category count: " + tFail);
            }
            LogWriter.info("Success import Category count: " + tSuccess);
        }
        catch (Exception ex) {
            LogWriter.error("下载产品类别时出错!");
            LogWriter.error(ex.getMessage());
        }       
        
    }

    /**{
     * 
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    }

}
